function dispatch(str) {
  // 任务队列
  var list = [];
  var list2 = [];

  list2.push(async () => {
    return new Promise(function(resolve, reject) {
      console.log(str);
      resolve();
    });
  });

  var run = async () => {
    var attr = [...list2, ...list];
    for (let i = 0; i < attr.length; i++) {
      const item = attr[i];
      await item();
    }
  };

  // 链式调用可操作对象
  var obj = {
    async println(val) {
      var fn = async () => {
        return new Promise(function(resolve, reject) {
          console.log(val);
          resolve();
        });
      };
      list.push(fn);
    },
    wait(time) {
      var fn = async () => {
        return new Promise(function(resolve, reject) {
          setTimeout(() => {
            resolve();
          }, time);
        });
      };
      list.push(fn);
      return obj;
    },

    waitFirst(time) {
      var fn = async () => {
        return new Promise(function(resolve, reject) {
          setTimeout(() => {
            resolve();
          }, time);
        });
      };
      list2.unshift(fn);
      return obj;
    },
  };

  setTimeout(() => {
    run();
  }, 0);
  return obj;
}

// dispatch("你好哈喽")
dispatch('你好哈喽')
  .waitFirst(3000)
  .wait(2000)
  .println('等待后的打印');

var current = () => {};

[
  () => {
    current();
    console.log(111);
    current = () => {};
  },
  2,
  3,
];
